public class stol {
	static int w_rece[] = new int[4];
	static int argumenty_graczy[][] = new int[4][5];
	static String kolory_graczy[][] = new String[4][5];
	static int ilosc = 0;

	static int wyloz_na_stol(int w_reka, int argumenty[], String karty[][]) {
		w_rece[ilosc] = w_reka;
		for (int i = 0; i < 5; i++) {
			argumenty_graczy[ilosc][i] = argumenty[i];
			kolory_graczy[ilosc][i] = karty[0][i];
		}
		ilosc++;
		return ilosc;
	}

	static int kto_wygral() {
		int wygral = 0;
		int min = 20;
		int l = 0;
		for (int i = 0; i < ilosc; i++) {
			if (min > w_rece[i]) {
				min = w_rece[i];
				l = 1;
			}
			if (min == w_rece[i])
				l++;
		}
		l--;
		if (l == 1) {
			for (int i = 0; i < ilosc; i++) {
				if (min == w_rece[i]) {
					wygral = i + 1;
					return i + 1;
				}
			}
		}
		if (l > 1) {
			int max = -1;
			for (int i = 0; i < 5; i++) {
				max = -1;
				int q = 0;
				int p = 0;
				for (int j = 0; j < l; j++) {
					if (min == w_rece[j]) {
						if (argumenty_graczy[j][i] > max) {
							max = argumenty_graczy[j][i];
							q = 1;
							p = i;
						}
						if (argumenty_graczy[j][i] == max)
							q++;
					}
				}
				q--;
				if (q == 1) {
					wygral = p + 1;
					return p + 1;
				}
				if (q > 1) {
					for (int j = 0; j < l; j++) {
						if (min == w_rece[j]) {
							if (argumenty_graczy[j][i] < max) {
								for (int m = 0; m < 5; m++)
									argumenty_graczy[j][m] = 0;
							}
						}
					}
				}
			}
		}
		return wygral;
	}
}
